package com.cskaoyan.controller;

import com.cskaoyan.bean.VO.WxCategoryVO;
import com.cskaoyan.bean.VO.WxGoodsDetailVO;
import com.cskaoyan.bean.VO.WxGoodsListVO2;
import com.cskaoyan.bean.VO.WxHomeIndexGoodsVO;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.WxGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微信端商品模块
 *
 * @author wenkaikai
 * @since 2022/08/16 10:43
 */


@RestController
@RequestMapping("wx/goods")
public class WxGoodsController {


    @Autowired
    WxGoodsService wxGoodsService;

    /**
     * 四个地方触发，商品list
     * 类目、品牌详情、新品首发,热点商品
     *
     * @return
     */
    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo info, Boolean isHot, Boolean isNew, Integer brandId, Integer categoryId) {
        WxGoodsListVO2 wxGoodsListVO = wxGoodsService.queryGoodsList(info, isHot, isNew, brandId, categoryId);
        return BaseRespVo.ok(0, wxGoodsListVO, "成功");
    }

    /**
     * 第一次进入小程序触发，计算商品总数
     *
     * @return
     */
    @RequestMapping("count")
    public BaseRespVo count() {
        long goodsNum = wxGoodsService.countGoodsNum();
        return BaseRespVo.ok(0, goodsNum, "成功");
    }

    /**
     * 类目、 参数id
     *
     * @return
     */
    @RequestMapping("category")
    public BaseRespVo category(Integer id) {
        WxCategoryVO wxCategoryVO = wxGoodsService.queryCategoryById(id);
        return BaseRespVo.ok(0, wxCategoryVO, "成功");
    }


    /**
     * 商品详情
     * 请求参数 id
     *
     * @return
     */
    @RequestMapping("detail")
    public BaseRespVo detail(Integer id) {
        WxGoodsDetailVO wxGoodsDetailVO = wxGoodsService.queryGoodsDetail(id);
        return BaseRespVo.ok(0, wxGoodsDetailVO, "成功");
    }

    /**
     * 商品详情页，显示相关商品,同二级目录下的
     * @return
     */
    @RequestMapping("related")
    public BaseRespVo related(Integer id) {
        CommonData<WxHomeIndexGoodsVO> commonData = wxGoodsService.queryRelatedGoods(id);
        return BaseRespVo.ok(0,commonData,"成功");
    }
}